import React from "react";

import PageContent from '../PageContent';

import { ajax, openErrorNotification, openSuccessNotification, showResultMessage, isNotNull, isNull } from '../common';

import BusinessProcessDataTablePanel from './BusinessProcessListTablePanel';

import BusinessProcessConfigPanel from './BusinessProcessConfigPanel';

/** 
 *  业务流程定义管理
*/
export default class BusinessProcessManageApp extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			currentTabKey: null,
		}
    }
    
    actionHandler = (actionEvent,panelInstance) => {

		return {
						        
			refresh : () => {
				panelInstance.loadData();
			},
									        
			addNew : () => {
				panelInstance.addNew();
			},
									        
			doDelete : () => {
				panelInstance.doDelete(isNotNull(actionEvent.params) ? actionEvent.params.id : null);
			},
													
			doEdit : () => {
				panelInstance.doEdit(actionEvent.params);
			},						
			doSave : () => {
				panelInstance.doSave();
			},
			configBusinessProcessNode : () =>{
				panelInstance.props.pageHistory.push('/configProcess',{process : actionEvent.params});
			},
												
		};
	}

	render() {

		const actionHandler = this.actionHandler;

		const pageContentMap = {
			'/': {
				text: '业务流程',
				icon: 'tasks',
				getComponent: function (owner, props) {
					return (
						<BusinessProcessDataTablePanel actionHandler={actionHandler} pageHistory={props.history}/>
					);
				}
			},
			'/configProcess': {
				text: '设置业务流程',
				icon: 'cogs',
				getComponent: function (owner, props) {
					return (
						<BusinessProcessConfigPanel {...props} pageHistory={props.history}/>
					);
				}
			}
		}

		return (
			<PageContent {...this.props} pageInstance={this} contentMap={pageContentMap}>

			</PageContent>
		);

    }
}